import requests
from lxml import etree
import pymongo

client = pymongo.MongoClient("mongodb://localhost:27017/")
db = client['ssr1']
collection = db['ssr1']


url = 'https://ssr1.scrape.center/'
response = requests.get(url)
print(response.text)

tree = etree.HTML(response.text)
imgs = tree.xpath('//div[@class="el-card__body"]//img')
title = tree.xpath('//div[@class="el-card__body"]//h2')
fs = tree.xpath('//div[@class="el-card__body"]//p[1]')
li = []
for i in range(len(title)):
    data = {
        'title': title[i].text,
        'img': imgs[i].attrib['src'],
        'fs': fs[i].text.strip()

    }
    li.append(data)

    # print(data)
print(li)
collection.insert_many(li)